window.document.oncontextmenu = function(event) {
  if (event.ctrlKey) return true;
  if (/Android|webOS|BlackBerry/i.test(navigator.userAgent)) return true;
  return popMenu(event);
};
document.addEventListener("click", function(event) {
  var mymenu = document.getElementById('SAO-back');
  mymenu.style.display = "none";
});
//点击菜单内元素播放点击音频
function clickAudio() {
  var clickAudio = document.getElementById("SAOClick");
  if (clickAudio) {
    clickAudio.play();
  }
}

function Mouseover() {
  var hasMenulist = event.target.querySelector('.menu-list');
  var hasMenuchild = event.target.querySelector('.menu-child');
  if (hasMenulist) {
    hasMenulist.classList.add('active');
  }
  if (hasMenuchild) {
    hasMenuchild.classList.add('active');
  }
}
// 
// function Mouseout() {
//   var hasMenulist = event.target.querySelector('.menu-list');
//   var hasMenuchild = event.target.querySelector('.menu-child');
//   if (hasMenulist && hasMenulist.className.indexOf('active') > -1) {
//     setTimeout(function() {
//       hasMenulist.classList.remove('active');
//     }, 5000);
//   }
//   if (hasMenuchild && hasMenuchild.className.indexOf('active') > -1) {
//     setTimeout(function() {
//       hasMenuchild.classList.remove('active');
//     }, 5000);
//   }
// }

function popMenu(event) {
  var audio = document.getElementById("SAOlauncher");
  if (audio) {
    audio.play();
  }
  document.getElementById('SAO-back').style.display = "block";
  var mymenu = document.getElementById('SAO-menu');
  var menuContent = document.getElementById('SAO-menu-content');
  var screenWidth = document.documentElement.clientWidth || document.body.clientWidth;
  var screenHeight = document.documentElement.clientHeight || document.body.clientHeight;
  mymenu.style.left = event.clientX + "px"; // 获取鼠标位置
  mymenu.style.top = event.clientY + "px";
  mymenu.style.display = 'block';
  //根据当前位置决定内容输出
  if (event.clientX * 2 > screenWidth) {
    mymenu.style.left = (event.clientX - menuContent.clientWidth) + "px"; // 获取鼠标位置
  } else {
    mymenu.style.left = event.clientX + "px";
  }
  if (event.clientY * 2 > screenHeight) {
    mymenu.style.top = (event.clientY - menuContent.clientHeight) + "px";
  } else {
    mymenu.style.top = event.clientY + "px";
  }
  return false;
}
